package scanner.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class InfFilter {
	
	public int getId(String str){
		int a=0; 
		Pattern p=Pattern.compile("\\d+");
		Matcher matcher=p.matcher(str);
		if(matcher.find()) {
			a=Integer.parseInt(str);	
		}else {
			a=0;             //若解析不出来，则默认为0
		}			
		return a;		
	}
	
	public String getName(String str){
		String rst=null;
		Pattern p=Pattern.compile("[a-zA-Z]+");
		Matcher matcher=p.matcher(str);
		if(matcher.find()) {
			rst=str;	
		}else {
			rst=null;             //若解析不出来，则默认为null
		}	
		return rst;		
	}
	
	public String getMail(String str){
		String rst=null;
		Pattern p=Pattern.compile("[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+");
		Matcher matcher=p.matcher(str);
		if(matcher.find()) {
			rst=str;	
		}else {
			rst=null;             //若解析不出来，则默认为null
		}
		return rst;		
	}
	
	public String getSex(String str){
		String rst=null;
		Pattern p=Pattern.compile("true|false");
		Matcher matcher=p.matcher(str);
		if(matcher.find()) {
			rst=str;	
		}else {
			rst="false";             //若解析不出来，则默认为false
		}

		return rst;		
	}
	
	public String getBirthday(String str){
		String rst=null;
		Pattern p=Pattern.compile("\\d{4}-\\d{1,2}-\\d{1,2}");
		Matcher matcher=p.matcher(str);
		if(matcher.find()) {
			rst=str;	
		}else {
			rst=null;             //若解析不出来，则默认为null
		}
		return rst;		
	}
	

}
